import request from '@/utils/request';
import { AxiosPromise } from 'axios';

// 获取业务编号
export const getReimburseNo = (params: any) => {
  return request({
    url: '/common/business/generateNo',
    method: 'get',
    params
  });
};
const moduleTypeArr = [] as const;
export type ModuleType = (typeof moduleTypeArr)[number];
export interface AttachmentQuery {
  moduleType: ModuleType;
  dataId: number;
}

export interface AttachmentVO {
  id: number; // 附件id
  moduleType: string; // 模块类型
  dataId: number; // 数据id
  fileName: string; // 文件名称
  serverFileName: string; // 服务端文件名称
  fileSize: number; // 文件大小
  createUserId: number; // 创建用户id
  createTime: string; // 创建时间
  previewUrl: string; // 预览地址
  formatFileSize: string; // 格式化文件大小 例如0B、12KB、1M、 3GB、2TB
}
// 查询附件列表
export function listAttachment(params: AttachmentQuery): AxiosPromise<AttachmentVO[]> {
  return request({
    url: '/attachment/list',
    method: 'get',
    params
  });
}

// 新增项目附件
export function addAttachment(params: AttachmentQuery, data: any) {
  return request({
    url: '/attachment',
    method: 'post',
    headers: {
      'Content-Type': 'multipart/form-data'
    },
    data,
    params
  });
}

// 删除项目附件
export function delAttachment(id: number) {
  return request({
    url: '/attachment/' + id,
    method: 'delete'
  });
}
